<?php
/* SVN FILE: $Id: index.ctp 36 2009-10-22 21:25:27Z kenreily@gmail.com $ */
/**
 * Short description for file.
 *
 * Long description for file
 *
 * PHP versions 4 and 5
 *
 * Recenseo: Online submission and reviewing for education
 * Copyright 2008-2009, Ken Reily
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * $Date: 2009-10-22 21:25:27 +0000 (Thu, 22 Oct 2009) $
 * $Revision: 36 $
 * $Author: kenreily@gmail.com $
 * $HeadURL: http://recenseo.googlecode.com/svn/trunk/app/views/assignments/index.ctp $
 */
  if (isset($assignments))
  {
    if ($user['User']['rating_type'] > 0) 
    {
      echo $html->tag('h3',
                      'Want feedback on your reviews? View your ' . $html->link('reviewer performance report',"/users/performance/{$course_id}") . '!',
                      array('style' => 'color:red'));
    }

?>
<h4>Course Assessments</h4>
<p>You have <?php echo $asmt_count; ?> incomplete assessment(s) for this course. <?php echo $html->link('Go to assessments.',"/assessments/index/{$course_id}"); ?></p>
<h4>Course Assignments</h4>
<p>The following is a list of assignments for this course:</p>
<table>
<?php
    echo $html->tableHeaders(array('Name',
                                   'Due Date/Time',
                                   'Cutoff Date/Time',
                                   'Your Submission / Score',
                                   'Your Ratings'));
  
    foreach ($assignments as $assignment)
    {
      $submission_id = null;

      foreach($user['Submission'] as $submission)
      {
        if ($submission['assignment_id'] == $assignment['Assignment']['id'] && $submission['active'] == 1)
        {
    	  $submission_id = $submission['id'];
        }
      }
    	
      if (empty($submission_id))
      {
        if (time() < strtotime($assignment['Assignment']['cutoff']))
    	{
    	  $submission_text = $html->link('Submit','/submissions/add/' . $assignment['Assignment']['id']);
    	}
    	else
    	{
    	  $submission_text = 'Missed';
    	}    	  
      }
      else
      {
        $submission_text = $html->link('View','/submissions/view/' . $submission_id);
      }

      if (empty($submission_id) || time() < strtotime($assignment['Assignment']['assessments_due']))
      {
        $ratings_text = '-';
      }
      else
      {
        $num_ratings = 0;

        foreach ($ratings as $rating)
        { 
          if ($rating['Assessment']['Submission']['assignment_id'] == $assignment['Assignment']['id'])
          {
            $num_ratings++;
          }
        }

        if (empty($assignment['Assignment']['required_ratings']))
        {
          $ratings_text = 'Not Required'; 
        }
        else if ($num_ratings >= $assignment['Assignment']['required_ratings'])
        {
          $ratings_text = 'Completed';
        }
        else
        {
	  $ratings_text = $html->link('Click to Complete',"/assessment_ratings/add/{$assignment['Assignment']['id']}");
        }
      }  

      echo $html->tableCells(array($assignment['Assignment']['name'],
                                   $time->nice($assignment['Assignment']['due']),
                                   $time->nice($assignment['Assignment']['cutoff']),
                                   $submission_text,
                                   $ratings_text),
                             array('class' => 'altrow'));
    }
  }
?>
</table>